package leetcode_1_200;

public class LeeCode_200 {
    public static void main(String[] args) {

    }
    private static int numIslands(char[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        int ans = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] == '0')
                    continue;
                dfs(grid, i, j);
                ans++;
            }
        }
        return ans;
    }
    private static void dfs(char[][] grid, int x, int y){
        if (y >= grid[0].length || y >= grid.length || x < 0 || y < 0)
            return;
        if (grid[x][y] == '1'){
            grid[x][y] = '0';
            dfs(grid, x + 1, y);
            dfs(grid, x - 1, y);
            dfs(grid, x, y + 1);
            dfs(grid, x, y - 1);
        }
    }
}
